import time

from getXybCode import code_queue
import requests
#从code_queue中取一个code
def loginAction(Cookie,encryptValue,openId,unionId):

    # 请求的 URL
    url = 'https://xcx.xybsyw.com/login/login.action'

    # 请求头
    headers = {
        'Host': 'xcx.xybsyw.com',
        'Connection': 'keep-alive',
        'wechat': '1',
        #t为十位时间戳
        't': str(int(round(time.time()))),
        'Cookie': Cookie,
        'content-type': 'application/x-www-form-urlencoded',
        'encryptValue': encryptValue,
        'm': '9c76cc502b6009afbd80ee6349d96921',
        'v': '1.6.36',
        'n': 'content,deviceName,keyWord,blogBody,blogTitle,getType,responsibilities,street,text,reason,searchvalue,key,answers,leaveReason,personRemark,selfAppraisal,imgUrl,wxname,deviceId,avatarTempPath,file,file,model,brand,system,deviceId,platform,code,openId,unionid,clockDeviceToken,clockDevice,address,name,enterpriseEmail,responsibilities,practiceTarget,guardianName,guardianPhone,practiceDays,linkman,enterpriseName,companyIntroduction,accommodationStreet,accommodationLongitude,accommodationLatitude,internshipDestination,specialStatement,enterpriseStreet,insuranceName,insuranceFinancing,policyNumber,overtimeRemark,riskStatement,specialStatement',
        's': '31_51_2_36_43_32_53_27_1_4_49_41_12_5_17_15_47_20_40_23',
        'Accept-Encoding': 'gzip,compress,br,deflate',
        'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.56(0x18003838) NetType/WIFI Language/zh_CN',
        'Referer': 'https://servicewechat.com/wx9f1c2e0bbc10673c/477/page-frame.html'
    }

    # 请求体数据
    data = {
        'username': '15776379355',
        'password': '430ebf279e3521cc1e80055f3db8e4fc',
        'openId': openId,
        'unionId': unionId,
        'model': 'iPhone <iPhone15,4>',
        'brand': 'iPhone',
        'platform': 'ios',
        'system': 'iOS 17.6.1',
        'deviceId': ''
    }

    try:
        # 发送 POST 请求
        response = requests.post(url, headers=headers, data=data)
        # 检查响应状态码
        response.raise_for_status()
        # 打印响应内容
        print(response.text)
    except requests.exceptions.HTTPError as http_err:
        print(f'HTTP 错误发生: {http_err}')
    except requests.exceptions.RequestException as req_err:
        print(f'请求发生错误: {req_err}')